package com.mallcloud.mall.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mallcloud.mall.common.core.constant.CacheConstants;
import com.mallcloud.mall.mall.api.entity.MallStoreModel;
import com.mallcloud.mall.mall.mapper.MallStoreMapper;
import com.mallcloud.mall.mall.service.MallStoreService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 门店
 */
@Service
public class MallStoreServiceImpl extends ServiceImpl<MallStoreMapper, MallStoreModel> implements MallStoreService {

	@Override
	@Cacheable(value = CacheConstants.STORE_DETAILS, unless = "#result.isEmpty()")
	public List<MallStoreModel> listStore(MallStoreModel dto) {
		return this.list(new LambdaQueryWrapper<>(dto));
	}

	@Override
	@Cacheable(value = CacheConstants.STORE_DETAILS, key = "#dto.storeNo", unless = "#result == null")
	public MallStoreModel getInfo(MallStoreModel dto) {
		return this.getOne(new LambdaQueryWrapper<MallStoreModel>()
				.eq(MallStoreModel::getStoreNo, dto.getStoreNo())
		);
	}

	@Override
	@CacheEvict(value = CacheConstants.STORE_DETAILS, allEntries = true)
	public Boolean saveStore(MallStoreModel storeModel) {
		return this.save(storeModel);
	}

	@Override
	@CacheEvict(value = CacheConstants.STORE_DETAILS, allEntries = true)
	public Boolean updateStore(MallStoreModel storeModel) {
		return this.updateById(storeModel);
	}

	@Override
	@CacheEvict(value = CacheConstants.STORE_DETAILS, allEntries = true)
	public Boolean removeStore(String storeNo) {
		return this.removeById(storeNo);
	}
}
